Imports PTT.CarRes.Data

Public Class ClassQuerypersonel_info
    Public Function Add(ByVal personel_info As Querypersonel_info) As Boolean
        Dim Clspersonel_info As New Classpersonel_info
        Dim Conn As OleDb.OleDbConnection
        Conn = Clspersonel_info.ConnectionOpen()
        Dim ret As Boolean = False
        With Clspersonel_info
            .CODE = personel_info.CODE
            .INAME = personel_info.INAME
            .FNAME = personel_info.FNAME
            .LNAME = personel_info.LNAME
            .FNAME_ENG = personel_info.FNAME_ENG
            .LNAME_ENG = personel_info.LNAME_ENG
            .BIRTHDATE = personel_info.BIRTHDATE
            .ADDRESS = personel_info.ADDRESS
            .HOMETEL = personel_info.HOMETEL
            .OFFICETEL = personel_info.OFFICETEL
            .SEX = personel_info.SEX
            .ENTRYDATE = personel_info.ENTRYDATE
            .WSTCODE = personel_info.WSTCODE
            .POSCODE = personel_info.POSCODE
            .UNITCODE = personel_info.UNITCODE
            .WGRPCODE = personel_info.WGRPCODE
            .JOBGROUP = personel_info.JOBGROUP
            .OFFICECODE = personel_info.OFFICECODE
            .STPOSDATE = personel_info.STPOSDATE
            .STJGDATE = personel_info.STJGDATE
            .JGAGE1 = personel_info.JGAGE1
            .JGAGE2 = personel_info.JGAGE2
            .AGE1 = personel_info.AGE1
            .AGE2 = personel_info.AGE2
            .POSAGE1 = personel_info.POSAGE1
            .POSAGE2 = personel_info.POSAGE2
            .JOBAGE1 = personel_info.JOBAGE1
            .JOBAGE2 = personel_info.JOBAGE2
            .RETIREYEAR = personel_info.RETIREYEAR
            .MGMT = personel_info.MGMT
            .V_UNITCODE = personel_info.V_UNITCODE
            .V_MGMT = personel_info.V_MGMT
            .C_MGMT = personel_info.C_MGMT
            .Lastupdate = personel_info.Lastupdate
            .UpdateBy = personel_info.UpdateBy
            .EmailAddr = personel_info.EmailAddr
            .Hiringdate = personel_info.Hiringdate
            ret = .USP_Save(Conn)
        End With
        Clspersonel_info.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal personel_info As Querypersonel_info) As Boolean
        Dim Clspersonel_info As New Classpersonel_info
        Dim Conn As OleDb.OleDbConnection
        Conn = Clspersonel_info.ConnectionOpen()
        Dim ret As Boolean = False
        With Clspersonel_info
            .CODE = personel_info.CODE
            .Load(Conn)
            .INAME = personel_info.INAME
            .FNAME = personel_info.FNAME
            .LNAME = personel_info.LNAME
            .FNAME_ENG = personel_info.FNAME_ENG
            .LNAME_ENG = personel_info.LNAME_ENG
            .BIRTHDATE = personel_info.BIRTHDATE
            .ADDRESS = personel_info.ADDRESS
            .HOMETEL = personel_info.HOMETEL
            .OFFICETEL = personel_info.OFFICETEL
            .SEX = personel_info.SEX
            .ENTRYDATE = personel_info.ENTRYDATE
            .WSTCODE = personel_info.WSTCODE
            .POSCODE = personel_info.POSCODE
            .UNITCODE = personel_info.UNITCODE
            .WGRPCODE = personel_info.WGRPCODE
            .JOBGROUP = personel_info.JOBGROUP
            .OFFICECODE = personel_info.OFFICECODE
            .STPOSDATE = personel_info.STPOSDATE
            .STJGDATE = personel_info.STJGDATE
            .JGAGE1 = personel_info.JGAGE1
            .JGAGE2 = personel_info.JGAGE2
            .AGE1 = personel_info.AGE1
            .AGE2 = personel_info.AGE2
            .POSAGE1 = personel_info.POSAGE1
            .POSAGE2 = personel_info.POSAGE2
            .JOBAGE1 = personel_info.JOBAGE1
            .JOBAGE2 = personel_info.JOBAGE2
            .RETIREYEAR = personel_info.RETIREYEAR
            .MGMT = personel_info.MGMT
            .V_UNITCODE = personel_info.V_UNITCODE
            .V_MGMT = personel_info.V_MGMT
            .C_MGMT = personel_info.C_MGMT
            .Lastupdate = personel_info.Lastupdate
            .UpdateBy = personel_info.UpdateBy
            .EmailAddr = personel_info.EmailAddr
            .Hiringdate = personel_info.Hiringdate
            ret = .USP_Update(Conn)
        End With
        Clspersonel_info.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal personel_info As Querypersonel_info) As Boolean
        Dim Clspersonel_info As New Classpersonel_info
        Dim Conn As OleDb.OleDbConnection
        Conn = Clspersonel_info.ConnectionOpen()
        Dim ret As Boolean = False
        With Clspersonel_info
            .CODE = personel_info.CODE
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        Clspersonel_info.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaCODE As String = "", _
    Optional ByVal ParaINAME As String = "", _
    Optional ByVal ParaFNAME As String = "", _
    Optional ByVal ParaLNAME As String = "") As Querypersonel_infos
        Dim Clspersonel_info As New Classpersonel_info
        Dim Conn As OleDb.OleDbConnection
        Conn = Clspersonel_info.ConnectionOpen()
        Dim ret As Querypersonel_infos = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from personel_info"
        If ParaCODE & "" <> "" Then
            If condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(CODE like '%" & ParaCODE & "%')"
        End If
        If ParaINAME & "" <> "" Then
            If condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(INAME like '%" & ParaINAME & "%')"
        End If
        If ParaFNAME & "" <> "" Then
            If condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(FNAME like '%" & ParaFNAME & "%')"
        End If
        If ParaLNAME & "" <> "" Then
            If condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(LNAME like '%" & ParaLNAME & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With Clspersonel_info
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New Querypersonel_infos
                Dim RBIRTHDATE As DateTime = Now
                Dim RENTRYDATE As DateTime = Now
                Dim RSTPOSDATE As DateTime = Now
                Dim RSTJGDATE As DateTime = Now
                Dim RLastupdate As DateTime = Now
                Dim RHiringdate As DateTime = Now

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)
                            If IsDate(.Item("BIRTHDATE")) Then
                                RBIRTHDATE = .Item("BIRTHDATE")
                            Else
                                RBIRTHDATE = now
                            End If
                            If IsDate(.Item("ENTRYDATE")) Then
                                RENTRYDATE = .Item("ENTRYDATE")
                            Else
                                RENTRYDATE = now
                            End If
                            If IsDate(.Item("STPOSDATE")) Then
                                RSTPOSDATE = .Item("STPOSDATE")
                            Else
                                RSTPOSDATE = now
                            End If
                            If IsDate(.Item("STJGDATE")) Then
                                RSTJGDATE = .Item("STJGDATE")
                            Else
                                RSTJGDATE = now
                            End If
                            If IsDate(.Item("Lastupdate")) Then
                                RLastupdate = .Item("Lastupdate")
                            Else
                                RLastupdate = now
                            End If
                            If IsDate(.Item("Hiringdate")) Then
                                RHiringdate = .Item("Hiringdate")
                            Else
                                RHiringdate = now
                            End If

                            results.Add(New Querypersonel_info( _
                              .Item("CODE") & "", _
                              .Item("INAME") & "", _
                              .Item("FNAME") & "", _
                              .Item("LNAME") & "", _
                              .Item("FNAME_ENG") & "", _
                              .Item("LNAME_ENG") & "", _
                              RBIRTHDATE, _
                              .Item("ADDRESS") & "", _
                              .Item("HOMETEL") & "", _
                              .Item("OFFICETEL") & "", _
                              .Item("SEX") & "", _
                              RENTRYDATE, _
                              .Item("WSTCODE") & "", _
                              .Item("POSCODE") & "", _
                              .Item("UNITCODE") & "", _
                              .Item("WGRPCODE") & "", _
                              .Item("JOBGROUP") & "", _
                              .Item("OFFICECODE") & "", _
                              RSTPOSDATE, _
                              RSTJGDATE, _
                              .Item("JGAGE1") & "", _
                              .Item("JGAGE2") & "", _
                              .Item("AGE1") & "", _
                              .Item("AGE2") & "", _
                              .Item("POSAGE1") & "", _
                              .Item("POSAGE2") & "", _
                              .Item("JOBAGE1") & "", _
                              .Item("JOBAGE2") & "", _
                              .Item("RETIREYEAR") & "", _
                              .Item("MGMT") & "", _
                              .Item("V_UNITCODE") & "", _
                              .Item("V_MGMT") & "", _
                              .Item("C_MGMT") & "", _
                              RLastupdate, _
                              .Item("UpdateBy") & "", _
                              .Item("EmailAddr") & "", _
                              RHiringdate _
                            ))
                        End With
                    Next
                    Ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        Clspersonel_info.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaCODE As String = "") As Querypersonel_infos
        Dim Clspersonel_info As New Classpersonel_info
        Dim Conn As OleDb.OleDbConnection
        Conn = Clspersonel_info.ConnectionOpen()
        Dim ret As Querypersonel_infos = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from personel_info"
        If ParaCODE & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(CODE = '" & ParaCODE & "')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With Clspersonel_info
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New Querypersonel_infos
                Dim RBIRTHDATE As DateTime = Now
                Dim RENTRYDATE As DateTime = Now
                Dim RSTPOSDATE As DateTime = Now
                Dim RSTJGDATE As DateTime = Now
                Dim RLastupdate As DateTime = Now
                Dim RHiringdate As DateTime = Now

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)
                            If IsDate(.Item("BIRTHDATE")) Then
                                RBIRTHDATE = .Item("BIRTHDATE")
                            Else
                                RBIRTHDATE = now
                            End If
                            If IsDate(.Item("ENTRYDATE")) Then
                                RENTRYDATE = .Item("ENTRYDATE")
                            Else
                                RENTRYDATE = now
                            End If
                            If IsDate(.Item("STPOSDATE")) Then
                                RSTPOSDATE = .Item("STPOSDATE")
                            Else
                                RSTPOSDATE = now
                            End If
                            If IsDate(.Item("STJGDATE")) Then
                                RSTJGDATE = .Item("STJGDATE")
                            Else
                                RSTJGDATE = now
                            End If
                            If IsDate(.Item("Lastupdate")) Then
                                RLastupdate = .Item("Lastupdate")
                            Else
                                RLastupdate = now
                            End If
                            If IsDate(.Item("Hiringdate")) Then
                                RHiringdate = .Item("Hiringdate")
                            Else
                                RHiringdate = now
                            End If

                            results.Add(New Querypersonel_info( _
                              .Item("CODE") & "", _
                              .Item("INAME") & "", _
                              .Item("FNAME") & "", _
                              .Item("LNAME") & "", _
                              .Item("FNAME_ENG") & "", _
                              .Item("LNAME_ENG") & "", _
                              RBIRTHDATE, _
                              .Item("ADDRESS") & "", _
                              .Item("HOMETEL") & "", _
                              .Item("OFFICETEL") & "", _
                              .Item("SEX") & "", _
                              RENTRYDATE, _
                              .Item("WSTCODE") & "", _
                              .Item("POSCODE") & "", _
                              .Item("UNITCODE") & "", _
                              .Item("WGRPCODE") & "", _
                              .Item("JOBGROUP") & "", _
                              .Item("OFFICECODE") & "", _
                              RSTPOSDATE, _
                              RSTJGDATE, _
                              .Item("JGAGE1") & "", _
                              .Item("JGAGE2") & "", _
                              .Item("AGE1") & "", _
                              .Item("AGE2") & "", _
                              .Item("POSAGE1") & "", _
                              .Item("POSAGE2") & "", _
                              .Item("JOBAGE1") & "", _
                              .Item("JOBAGE2") & "", _
                              .Item("RETIREYEAR") & "", _
                              .Item("MGMT") & "", _
                              .Item("V_UNITCODE") & "", _
                              .Item("V_MGMT") & "", _
                              .Item("C_MGMT") & "", _
                              RLastupdate, _
                              .Item("UpdateBy") & "", _
                              .Item("EmailAddr") & "", _
                              RHiringdate _
                            ))
                        End With
                    Next
                    Ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        Clspersonel_info.ConnectionClose(Conn)
        Return ret
    End Function
End Class